package com.kitty.game.rank.model.pojo;

import com.kitty.game.rank.model.RankData;
import com.kitty.game.rank.model.RankType;
import com.kitty.game.rank.model.record.RankRecord;
import com.kitty.game.utils.JsonUtils;
import org.codehaus.jackson.type.TypeReference;

import java.util.List;

/**排行数据，用于加载保存*/
public class RankListData extends RankData {
    private RankType rType;
    private List<RankRecord> rankData;

    public RankListData() {}

    public RankListData(RankType rType, List<RankRecord> rankData) {
        this.rType = rType;
        this.rankData = rankData;
    }

    public List<RankRecord> getRankData() {
        return this.rankData;
    }

    public void setRankData(List<RankRecord> rankData) {
        this.rankData = rankData;
    }

    public void doAfterInit() {
//        this.rankData = JSON.parseObject(data, new TypeReference<List<T>>(clazz){});
        this.rankData = JsonUtils.string2Collection(data, List.class, RankRecord.class);
    }

    public void doBeforeSave() {
        this.type = rType.name();
        this.data = JsonUtils.object2String(rankData, new TypeReference<List<RankRecord>>(){});
    }
}
